p = input().split()
f = 0
f1 = 0
f2 = 0
c = ""
wr = 0
m = 2
if len(p) != 3:
    print("Wrong input")
    wr = 1
else:
    for i in range(3):
        if p[f] == "zero":
            c += str(0)
        elif p[f] == "one":
            c += str(1)
        elif p[f] == "two":
            c += str(2)
        elif p[f] == "three":
            c += str(3)
        elif p[f] == "four":
            c += str(4)
        elif p[f] == "five":
            c += str(5)
        elif p[f] == "six":
            c += str(6)
        elif p[f] == "seven":
            c += str(7)
        elif p[f] == "eight":
            c += str(8)
        elif p[f] == "nine":
            c += str(9)
        else:
            print("Wrong input")
            wr = 1
            break
        f += 1
if wr == 0:
    s = int(c)
    f = 0
if wr == 0:
    while f == 0:
        m = 2
        while m < s:
            if s % m == 0:
                s = s - 1
                break
            elif s % m != 0:
                m += 1
            if m == (s - 2):
                f = 1
                break
        f1 += 1
    s = int(c)
    f = 0
    while f == 0:
        m = 2
        while m < s:
            if s % m == 0:
                s += 1
                break
            elif s % m != 0:
                m += 1
            if m == s - 2:
                f = 1
                break
        f2 += 1
if wr == 0:
    f1 = f1 -1
    f2 = f2 - 1
    if f1 < f2:
        print(int(c) - f1)
    elif f1 > f2:
        print(int(c) + f2)
    elif f1 == f2:
        print(int(c) - f1)